package com.sanalkitaplik.hibernateutil;

import java.util.List;
import java.util.Scanner;

import javax.swing.JOptionPane;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import com.sanalkitaplik.packageclassdto.UsersLoginInfoDTO;


public class Deneme {
	
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		System.out.println("kullanıcı adını ve şifreyi giriniz: ");
		String k_a=s.next();
		String sfr = s.next();
		System.out.println("doğru mu? -> "+AdminsUtil.loginCheck(k_a, sfr));
	}
	private static void vt(String k_a, String sfr) throws HibernateException{
		Session s = SessionFactoryBuilder.getSessionFactory().openSession(); System.out.println("SESSION ->"+ s);
		UsersLoginInfoDTO dao = null;
		try{
			Query query = s.createSQLQuery("select * from SNLKTPLK_USERS_LOGIN_INFO where USERNAME="+k_a+" and USER_PASSWORD="+sfr+"");
			
			System.out.println(query);
			if(query==null)System.out.println("null");
			else System.out.println("dolu");
			
			int kontrol = 0;
			List list = query.list();
			
			for(int i=1;i<=list.size();i++){
				dao = (UsersLoginInfoDTO)s.load(UsersLoginInfoDTO.class, i);
	            if(k_a.equalsIgnoreCase(dao.getUsername())){
	            	if(sfr.equalsIgnoreCase(dao.getUser_password())){
	            		kontrol++;
		            	System.out.println("buldu!!");
		            	break;
	            	}
	            }       
			}System.out.println("bulamadı!!");
			if(kontrol == 0){
				JOptionPane.showMessageDialog(null, "kiSi sistemde kayItlI dEGildir.","HATA",JOptionPane.WARNING_MESSAGE);
			}	
		}
		catch(Exception ex){
			System.out.println("Bilgi göstermede hata :" +ex.getMessage());
		}
		finally{
			
			s.flush();
			s.close();
		}
		
	}
}
